Imports System.Net.Mail
Imports System.Configuration

Partial Class Controls_ContactPanel
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles Me.Load

        If Not Me.Page.IsPostBack Then
            pnlContactForm.Visible = True
            pnlThankYou.Visible = False
        End If

    End Sub

    Protected Sub btnSend_Click(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles btnSend.Click

        If Me.Page.IsValid Then

            Dim mailFrom As String = txtEmail.Text
            Dim mailTo As String = ConfigurationManager.AppSettings("mailTo")
            Dim mailSubject As String = "Enquiry From " & txtName.Text

            Dim mailBody As String = IO.File.ReadAllText(Server.MapPath("mailBase.txt"))
            mailBody = mailBody.Replace("|NAME|", txtName.Text)
            mailBody = mailBody.Replace("|EMAIL|", mailFrom)
            mailBody = mailBody.Replace("|MESSAGE|", txtEnquiry.Text)

            Dim c As New SmtpClient(ConfigurationManager.AppSettings("hostName"))
            Dim m As New MailMessage(mailFrom, mailTo, mailSubject, mailBody)

            c.Send(m)

            pnlContactForm.Visible = False
            pnlThankYou.Visible = True

        End If

    End Sub
End Class
